package com.lanswon.qzsmk.controller.cardManageController;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import ch.qos.logback.classic.Logger;

import com.lanswon.qzsmk.base.CardContants;
import com.lanswon.qzsmk.base.HttpContants;
import com.lanswon.qzsmk.base.PathContants;
import com.lanswon.qzsmk.dao.CardProdunctDefinitionMapper;
import com.lanswon.qzsmk.exception.ApplicationException;
import com.lanswon.qzsmk.exception.SystemException;
import com.lanswon.qzsmk.model.ActiveUser;
import com.lanswon.qzsmk.model.AddressArea;
import com.lanswon.qzsmk.model.AddressCity;
import com.lanswon.qzsmk.model.AddressProvince;
import com.lanswon.qzsmk.model.AddressStreet;
import com.lanswon.qzsmk.model.CardPhysicsType;
import com.lanswon.qzsmk.model.CardProdunctDefinition;
import com.lanswon.qzsmk.model.CollAttach;
import com.lanswon.qzsmk.model.FeeRules;
import com.lanswon.qzsmk.model.Nation;
import com.lanswon.qzsmk.model.PaperType;
import com.lanswon.qzsmk.model.Personal;
import com.lanswon.qzsmk.service.appManageService.AppFeeService;
import com.lanswon.qzsmk.service.cardManageService.ApplyCardService;
import com.lanswon.qzsmk.service.systemManageService.ParamManageService;
import com.lanswon.qzsmk.util.FtpUtil;
import com.lanswon.qzsmk.vo.ApplicationParm;
import com.lanswon.qzsmk.vo.FeeRulesVo;
import com.lanswon.qzsmk.vo.ResultObject;
import com.lanswon.qzsmk.vo.ResultVo;
import com.lanswon.qzsmk.vo.VoucherVo;


/**
 * 卡单笔申请controller类
 * @author Guyw
 *
 */
@Controller
@RequestMapping(value="/applicationSingle")
public class ApplicationSingleController {
	
	//20180131 惠国磊 以下1行  增加
	private final static Logger logger = (Logger) LoggerFactory.getLogger(ApplicationSingleController.class);
	
	@Autowired
	ApplyCardService acs;
	
	@Autowired
	ParamManageService pm;
	
	@Autowired
	AppFeeService afs;
	
	@Autowired
	CardProdunctDefinitionMapper cdm;
	
	//20180223 惠国磊  以下20行 新建
	/**
	 * 上传证件附件
	 * @param file 前端页面上传的文件
	 * @param request
	 * @return 
	 */
//	@RequiresPermissions("applicationSingle:uploadFile")
//	@RequestMapping(name="单笔申请上传证件附件,applicationSingle:uploadFile",value="/uploadFile",method=RequestMethod.POST)
//	@ResponseBody
//	public Map<String,Object> uploadPaperFile(MultipartFile file,HttpServletRequest request){
//		logger.debug("uploadPaperFile########start()");
//		//获取到上传文件的名字
//		String fileName = file.getOriginalFilename();
//		//获取证件号码
//		String paperNo = fileName.substring(0, fileName.indexOf("_"));
//		logger.debug("证件号码==>"+paperNo);
//		logger.debug("上传的文件名字====>"+fileName);
//		String targetPath = "D:\\Apache24\\htdocs\\qzsmk\\resource\\unEnclosures\\"+paperNo;
//		//设置文件夹的名称
//		
//	//	String path = sourcePath +File.separator+ fileName;
//	    File localFile = new File(targetPath);
//	    if(!localFile.exists()){
//	    	localFile.mkdirs();
//	    	logger.debug("文件夹创建完毕！！！");
//	    }
//	    File targetFile = new File(targetPath+"\\"+fileName);
//	    try {
//			file.transferTo(targetFile);
//		} catch (IllegalStateException e) {
//	         e.printStackTrace();
//			String msg="系统上传文件异常";
//			logger.error(msg);
//			throw new SystemException(SystemException.IllegalStateException, msg);
//
//		} catch (IOException e) {
//	         e.printStackTrace();
//			String msg="系统上传文件异常";
//			logger.error(msg);
//			throw new SystemException(SystemException.IOException, msg);
//
//		}
//	    
//	    String sourcePath = "D:\\Apache24\\htdocs\\qzsmk\\resource\\temple\\"+ paperNo+"\\"+fileName;
//	    File localFiles = new File(sourcePath);
//	    localFiles.delete();
//         
//		logger.debug("uploadPaperFile########end()");
//		//20180213 惠国磊 简单测试 后期修改完善
//		Map<String, Object> map=new HashMap<>();
//		map.put("file", "123456");
//		return map;
//	}
//	
	//20180223 惠国磊  以下20行 新建
	/**
	 * 上传采集单附件
	 * @param file 前端页面上传的文件
	 * @param request
	 * @return
	 */
	@RequiresPermissions("applicationSingle:uploadAppRegFile")
	@RequestMapping(name="单笔申请上传采集单附件,applicationSingle:uploadAppRegFile",value="/uploadAppRegFile",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> uploadAppRegFile(@RequestParam("files")MultipartFile[] files,HttpServletRequest request){
		logger.debug("uploadAppRegFile########start()");
		Map<String, Object> map=new HashMap<>();
		//获取到上传文件的名字 320721199108155211_采集表.pdf
		String root = request.getSession().getServletContext().getRealPath("/");
//		Personal p =  (Personal) request.getSession().getAttribute("p");
		String collectionId = (String) request.getSession().getAttribute("CollectionId");
		List<CollAttach> list = new ArrayList<>();
		for(MultipartFile file:files){
			String name = file.getOriginalFilename();
			String type = name.substring(name.indexOf(".")+1);
			String paperNo = name.substring(0,name.indexOf("_"));
			File ff = new File(root + PathContants.PROJECT_PATH_ENCLOSURE_IMPORTED + File.separator + paperNo);
			String path = PathContants.PROJECT_PATH_ENCLOSURE_IMPORTED + File.separator + paperNo +File.separator+name;
			if (!ff.exists()) {
				ff.mkdirs();
			}
			try {
				file.transferTo(new File(ff.getAbsolutePath()+File.separator+name));
				CollAttach ca = new CollAttach();
				ca.setCollAttachId(UUID.randomUUID().toString().replace("-", ""));
				ca.setAttachContent(path);
				ca.setAttachType( CardContants.getFileTypeCodeByFileSuffix(type));// 0圖片，1pdf
				ca.setCollectionId(collectionId);
//				ca.setCustomerNo(p.getCustomerNo());
	//			request.getSession().setAttribute("flag", true);
				list.add(ca);
			
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("上传失败");
				map.put("statusCode", "300");
				map.put("message", "系统上传文件失败");
				return map;
			} 
		}
		
		acs.saveSingleEnclosure(list);
		//20180213 惠国磊 简单测试 后期修改完善
		map.put("statusCode", "200");
		map.put("message", "上传成功");
		map.put("callbackType", "closeCurrent");
		logger.debug("uploadAppRegFile########end()");
		return map;
	}
	
	@RequiresPermissions("applicationSingle:takePhotoIndex")
	@RequestMapping(value="/takePhotoIndex/{param}",name="拍照页面,applicationSingle:takePhotoIndex",method={RequestMethod.POST,RequestMethod.GET})
	public String takePhotoIndex(@PathVariable String param,HttpServletRequest request){
		System.out.println(param);
		request.getSession().setAttribute("photoName", param.split("-")[0]);
		request.getSession().setAttribute("paperType", param.split("-")[1]);
		return "TakePhoto";
	}
	
	@RequestMapping(value="/getRealPath",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> getRealPath(HttpServletRequest request){
		Map<String, String>map=new HashMap<>();
		map.put("photoPath", request.getSession().getServletContext().getRealPath(PathContants.PROJECT_PATH_IMG_IMPORTED)+File.separator);
		map.put("enclosurePath", request.getSession().getServletContext().getRealPath(PathContants.PROJECT_PATH_ENCLOSURE_IMPORTED)+File.separator);
		map.put("photoPath2",PathContants.PROJECT_PATH_IMG_IMPORTED+File.separator);//show路径
		map.put("enclosurePath2", PathContants.PROJECT_PATH_ENCLOSURE_IMPORTED+File.separator);//show路径
		map.put("photoName", (String)request.getSession().getAttribute("photoName"));
		return map;
	}
	
	@RequiresPermissions("applicationSingle:uploadImage")
	@ResponseBody
	@RequestMapping(value="/uploadImage",name="上传照片,applicationSingle:uploadImage",method=RequestMethod.POST)
	public Map<String, Object>uploadImage(String image,HttpServletRequest request) throws IOException{
		Map<String, Object>map=new HashMap<>();
		String absoluteRoot=request.getSession().getServletContext().getRealPath("/");
		String relativeRoot = request.getSession().getServletContext().getContextPath();
		String photoName=(String) request.getSession().getAttribute("photoName");//照片名就是证件号
		String paperType=(String) request.getSession().getAttribute("paperType");
		request.getSession().removeAttribute("paperType");
		String photoType=".png";
		ResultVo resultVo=acs.uploadImageByApplicationSingle(image,absoluteRoot,PathContants.PROJECT_PATH_IMG_IMPORTED, photoName,photoType,paperType);
		if(resultVo.getResultStatus().getCode()==HttpContants.RETURN_SUCCESS){
			map.put("statusCode", HttpContants.RETURN_SUCCESS);
			map.put("message", resultVo.getResultStatus().getMessage());
			String photoPath=relativeRoot+PathContants.PROJECT_PATH_IMG_IMPORTED+File.separator+photoName+photoType;
			map.put("photoPath",photoPath);
		}else{
			map.put("statusCode", "300");
			map.put("message", "上传失败");
		}
		return map;
	}
	
//	@RequiresPermissions("applicationSingle:lookPhotoIndex")
//	@RequestMapping(value="/lookPhotoIndex/{photoName}",name="查看头像,applicationSingle:lookPhotoIndex",method={RequestMethod.POST,RequestMethod.GET})
//	public String lookPhotoIndex(@PathVariable String photoName,HttpServletRequest request){
//		System.out.println("photoName===========>>"+photoName);
//		request.getSession().setAttribute("photoName", photoName);
//		return "LookPhoto";
//	}
	
	/**
	 * 显示头像
	 * @param request
	 * @return
	 */
//	@RequiresPermissions("applicationSingle:showImage")
//	@ResponseBody
//	@RequestMapping(value="/showImage",method=RequestMethod.POST,name="显示头像,applicationSingle:showImage")
//	public Map<String, Object>showImage(HttpServletRequest request){
//		Map<String, Object> map=new HashMap<>();
//		String photoName=(String) request.getSession().getAttribute("photoName");
//		System.out.println(photoName+"<<<<<====================");
//		request.getSession().removeAttribute("photoName");
//		map.put("photoName", photoName);
//		return map;
//	}
		
	/**
	 * 纯粹跳转连接用的方法(跳转到登记页面)
	 * @return
	 */
	@RequiresPermissions("applicationSingle:register")
	@RequestMapping(name="单笔申请登记页面,applicationSingle:register",value="/register",method=RequestMethod.POST)
	public String ApplicationRegister(HttpServletRequest request){
		logger.info("ApplicationRegister_POST########start()");
		request.getSession().setAttribute("shgn", true);
		request.getSession().setAttribute("flag", false);
		logger.info("ApplicationRegister_POST########end()");
		return "ApplicationRegister";
	}
	
	@RequiresPermissions("applicationSingle:register")
	@RequestMapping(name="单笔申请登记页面,applicationSingle:register",value="/register",method=RequestMethod.GET)
	public String ApplicationRegisters(HttpServletRequest request){
		logger.info("ApplicationRegister_GET########start()");
		request.getSession().setAttribute("shgn", false);
		logger.info("ApplicationRegister_GET########end()");
		return "ApplicationRegister";
	}
	
	/**
	 * 返回申请信息
	 * @param 
	 * @return
	 */
	@RequiresPermissions("applicationSingle:register")
	@RequestMapping(value="/getUpdateApplicationSingle",name="单笔申请登记页面,applicationSingle:getUpdateApplicationSingle",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> getUpdateInfo(HttpServletRequest request){
		Map<String, Object> map=new HashMap<>();
		map.put("shgn", request.getSession().getAttribute("shgn"));
		map.put("p", request.getSession().getAttribute("p"));
		request.getSession().removeAttribute("shgn");
		request.getSession().removeAttribute("p");
		return map;
	}
	
	/**
	 * 跳转单笔申请页面
	 * @return
	 */
	@RequiresPermissions("applicationSingle:index")
	@RequestMapping(name="单笔申请页面,applicationSingle:index",value="/single",method={RequestMethod.GET,RequestMethod.POST})
	public String ApplicationSinge(HttpServletRequest request){
		logger.info("ApplicationSinge########start()");
		String param = request.getParameter("param");
		logger.debug("param==>"+param);
		//放入session中
		request.getSession().removeAttribute("param");
		request.getSession().setAttribute("param", param);
		logger.info("ApplicationSinge########end()");
		return "ApplicationSingle";
	}
		
	//20180203 惠国磊 以下chargeMoney方法  初版
	/**
	 * 跳转上传页面
	 * @return
	 */
	@RequiresPermissions("applicationSingle:chargePage")
	@RequestMapping(name="单笔上传页面,applicationSingle:chargePage",value="/chargePage",method=RequestMethod.GET)
	public String chargeMoney(){
		return "ApplicationUpload";
	}
	

	//2018.2.2 鱼洲杰 以下50行 初版
		/**
		 * 记录信息并跳转收费页面
		 * @throws Exception 
		 * @throws ApplicationException 
		 *//*
		@RequestMapping(value="/toCharge",method=RequestMethod.POST)
		@ResponseBody
			public  Map<String, Object> credentials( HttpServletRequest request,Personal p,String birth,String cardCode,String cardTypeCode) throws  Exception {
			logger.info("credentials########start()");
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			Date date =sdf.parse(birth);
			p.setBirthday(date);//出生日期
			logger.debug("p==>"+p);
			request.getSession().removeAttribute("p");
			request.getSession().removeAttribute("cardCode");
			request.getSession().removeAttribute("cardTypeCode");
			
			request.getSession().setAttribute("p", p);
			request.getSession().setAttribute("cardCode", cardCode);
			request.getSession().setAttribute("cardTypeCode", cardTypeCode);
			//acs.singleApplication( p, cardCode, cardTypeCode);
			//acs.singleApplication(request.getServletContext().getRealPath("/"), p, cardCode, cardTypeCode);
			Map<String, Object> map=new HashMap<>();
			map.put("statusCode", "200");
			map.put("callbackType", "forward");
			map.put("forwardUrl", "applicationSingle/chargePage");
			logger.info("credentials########end()");
			return map;
		}*/
	/**
	 * 登记信息插入数据库并跳转凭证页面
	 * @throws Exception 
	 * @throws ApplicationException 
	 */
	@RequestMapping(value="/toCharge",method=RequestMethod.POST)
	@ResponseBody
		public  Map<String, Object> credentials( HttpServletRequest request,Personal p,String birth,String cardCode,String cardTypeCode) throws  Exception {
		logger.info("credentials########start()");
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		Date date =sdf.parse(birth);
		p.setBirthday(date);//出生日期
		ResultVo vv = acs.singleApplication( p, cardCode, cardTypeCode);
		/*Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("applyType", "applyRegister");
		paramMap.put("credentialVo", (VoucherVo)vv.getServiceObject());*/
		Map<String, Object> map=new HashMap<>();
		if(vv.getResultStatus().getCode()==HttpContants.RETURN_SUCCESS){
			/*map.put("statusCode", "200");
			map.put("max", "true");
			map.put("rel", "applicationCert");
			map.put("title", "申领凭证");
			map.put("param", paramMap);
			map.put("navTabId", "ApplicationSingle");
			map.put("url", "printCredentials/toPdfView");*/
			request.getSession().setAttribute("vo", (VoucherVo)vv.getServiceObject());
			request.getSession().setAttribute("type", "applyRegister");
			map.put("max", "true");
	        map.put("title", "申领凭证");
	        map.put("rel", "applyRegister");
	        map.put("statusCode", "200");
	        map.put("url", "printCredentials/toHairpinPdfView");
	        //20181206 hgl 以下三行
	        map.put("jumpToTabid", "ApplicationSingle");
	        map.put("jumpToUrl", "applicationSingle/single");//
	        map.put("jumpToTile", "单笔申请");
	        
		}else{//页面获取异常信息
			map.put("statusCode", "300");
			map.put("message",vv.getResultStatus().getMessage());
		}
		
		logger.info("credentials########end()");
		return map;
	}
		/**
		 * 登记信息插入数据库
		 * @throws Exception 
		 * @throws ApplicationException 
		 *//*
		@RequestMapping(value="/toDatabaseRegistry",method=RequestMethod.POST)
		@ResponseBody
			public  Map<String, Object> databaseRegistry( HttpServletRequest request){
			logger.info("databaseRegistry########start()");
			Personal p=(Personal) request.getSession().getAttribute("p");
			String cardCode=(String) request.getSession().getAttribute("cardCode");
			String cardTypeCode=(String) request.getSession().getAttribute("cardTypeCode");
			ResultVo vv = acs.singleApplication( p, cardCode, cardTypeCode);
			Map<String,Object> paramMap = new HashMap<String,Object>();
			paramMap.put("applyType", "applyRegister");
			paramMap.put("credentialVo", (VoucherVo)vv.getServiceObject());
			Map<String, Object> map=new HashMap<>();
			if(vv.getResultStatus().getCode()==HttpContants.RETURN_SUCCESS){
				map.put("statusCode", "200");
				map.put("max", "true");
				map.put("rel", "applicationCert");
				map.put("title", "申领凭证");
				map.put("param", paramMap);
				map.put("navTabId", "ApplicationSingle");
				map.put("url", "printCredentials/toPdfView");
				logger.info("databaseRegistry########end()");
			}else{//页面获取异常信息
				map.put("statusCode", "300");
				map.put("message",vv.getResultStatus().getMessage());
			}
			
			return map;
		}*/
	
	/**
	 * 验证申请人能否办卡
	 * @param 证件类型，证件号，物理卡类型，卡产品代码
	 * @return 
	 * @throws Exception 
	 */
	@RequiresPermissions("applicationSingle:validateInfo")
	@RequestMapping(name="单笔申请验证申请人能否办卡,applicationSingle:validateInfo",value="/validate",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> validateInfo(String PaperType,String PaperNo,String CdPhysicsType,String CardCode,HttpServletRequest request) throws Exception{
		System.out.println(PaperType+","+PaperNo+","+CdPhysicsType+","+CardCode);		
		CardPhysicsType cpT=pm.queryCardPhysicsTypeByCode(CdPhysicsType);//卡物理类型		
		CardProdunctDefinition cpd=pm.queryCardPCode(CardCode);//卡产品		
		PaperType pt=pm.queryPaperByPaperTypeCode(PaperType);//证件类型		
		ApplicationParm aParm=new ApplicationParm(PaperNo, PaperType, CardCode, CdPhysicsType);//提交参数类
		aParm.setCardpName(cpd.getCardpName());
		aParm.setCardType(cpT.getCardTypeName());
		aParm.setPaperType(pt.getCertificatesName());
		Map<String,Object>map=new HashMap<String,Object>();
	//如果已经办理了相同的卡产品提示页面
		ResultVo resultVo = acs.checkIsCardProductbyPaperNo(PaperType, PaperNo, CardCode);
		if(resultVo.getResultStatus().getCode()==HttpContants.RETURN_SUCCESS){
			ResultObject ro = (ResultObject) resultVo.getServiceObject();
			if(ro.getVariable()==1){
				logger.debug("未办理过！！");
				logger.debug("aParm"+aParm.toString());
				//20180509 惠国磊 增加1行
				request.getSession().removeAttribute("Personal");
				//从未办理过
				request.getSession().setAttribute("AppParm", aParm);
				map.put("statusCode", "200");
				map.put("callbackType", "forward");
				map.put("forwardUrl", "applicationSingle/register");
			}else if(ro.getVariable()==2){
				//办理过该卡产品，但已经注销
				ResultVo p= null;
				if("00".equals(PaperType)){
					 p = acs.queryPersonalByPaperNoAndPaperType(PaperType, PaperNo);
					 if(p == null){
						 p = acs.queryPersonalByPaperNoAndPaperType("01", PaperNo);
					 } 
				}else if( "01".equals(PaperType)){
					p = acs.queryPersonalByPaperNoAndPaperType(PaperType, PaperNo);
					 if(p == null){
						 p = acs.queryPersonalByPaperNoAndPaperType("00", PaperNo);
					 }
				}else{
					p = acs.queryPersonalByPaperNoAndPaperType(PaperType, PaperNo);
				}
				//aParm.setBirthday(dateFormat((Personal)p.getServiceObject()));
			 	request.getSession().setAttribute("Personal", (Personal)p.getServiceObject());
			 	request.getSession().setAttribute("AppParm", aParm);
			 	map.put("statusCode", "200");
				map.put("callbackType", "forward");
				map.put("forwardUrl", "applicationSingle/register");
			}
			
		}else{
			int a =resultVo.getResultStatus().getCode();
			if(a == 3){
				//该卡产品还在使用
				map.put("statusCode", "300");
				map.put("message", "您已成功领取该卡,请勿重复办理");
			}
			if(a == 4){
				//已申请
				map.put("statusCode", "300");
				map.put("message", "您已成功申请该卡,请勿重复申请");
			}
		}
		return map;
	}
	
	/**
	 * 页面加载省
	 * @param request
	 * @return
	 */
	@RequiresPermissions("applicationSingle:getProInfo")
	@RequestMapping(name="单笔申请页面加载省,applicationSingle:getProInfo",value="/pro",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> pro(String select,HttpServletRequest request){
		System.out.println("1111122222"+select);
		List<AddressProvince> AddressProvince=pm.queryAddressProvince();//省集合
		System.out.println(AddressProvince);
		Map<String, Object> map=new HashMap<>();
		map.put("AddressProvince", AddressProvince);
		
		System.out.println(map);
		return map;

	}
	/**
	 * 页面加载市
	 * @param request
	 * @return
	 * @throws ApplicationException 
	 */
	@RequiresPermissions("applicationSingle:getCityInfo")
	@RequestMapping(name="单笔申请页面加载市,applicationSingle:getCityInfo",value="/city",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> city(String selectId,HttpServletRequest request ) throws ApplicationException{
		List<AddressCity> AddressCity=pm.queryAddressCityByFatherId(selectId);//市集合
		Map<String, Object> map=new HashMap<>();
		map.put("AddressCity", AddressCity);
		return map;

	}
	/**
	 * 页面加载区/县
	 * @param request
	 * @return
	 * @throws ApplicationException 
	 */
	@RequiresPermissions("applicationSingle:getCountyInfo")
	@RequestMapping(name="单笔申请页面加载镇/街道,applicationSingle:getCountyInfo",value="/county",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> county(String selectId,HttpServletRequest request ) throws ApplicationException{
		List<AddressArea> AddressArea=pm.queryAddressAreaByFatherId(selectId);//市集合
		Map<String, Object> map=new HashMap<>();
		map.put("AddressArea", AddressArea);
		return map;

	}
	/**
	 * 页面加载镇/街道
	 * @param request
	 * @return
	 * @throws ApplicationException 
	 */
	@RequiresPermissions("applicationSingle:getAreaInfo")
	@RequestMapping(name="单笔申请页面加载镇/街道,applicationSingle:getAreaInfo",value="/area",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> area(String selectId,HttpServletRequest request ) throws ApplicationException{
		List<AddressStreet> AddressStreet=pm.queryAddressStreetByFatherId(selectId);//市集合
		Map<String, Object> map=new HashMap<>();
		map.put("AddressStreet", AddressStreet);
		return map;

	}
	/**
	 * 页面加载民族
	 * @param request
	 * @return
	 * @throws 
	 */
	@RequiresPermissions("applicationSingle:getNationInfo")
	@RequestMapping(name="单笔申请页面加载民族,applicationSingle:getNationInfo",value="/nation",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> nation(HttpServletRequest request ) {
		Map<String, Object> map=new HashMap<>();

		ResultVo rv = pm.queryNation();
		if(rv.getResultStatus().getCode() == HttpContants.RETURN_SUCCESS){
			ResultObject ro = (ResultObject) rv.getServiceObject();
			List<Nation> Nation=(List<Nation>) ro.getItems();
			map.put("Nation", Nation);
		}else{
			map.put("statusCode", "300");
			map.put("message", "民族获取异常");
		}
		
		
		return map;

	}
	/**
	 * 页面加载时通过ajax获取session数据，实现单笔申请登记动态页面展示
	 * @param request
	 * @return
	 * @throws ApplicationException 
	 */
	@RequiresPermissions("applicationSingle:getRegisterInfo")
	@RequestMapping(name="单笔申请登记页面信息,applicationSingle:getRegisterInfo",value="/getinfoByApplicationRegister",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getinfo(HttpServletRequest request) throws ApplicationException{
		System.out.println("goin");
		String root = request.getSession().getServletContext().getRealPath("/");

		Map<String, Object> map=new HashMap<>();
		Personal p=(Personal) request.getSession().getAttribute("Personal");
		ApplicationParm aParm=(ApplicationParm) request.getSession().getAttribute("AppParm");
		String path=root + PathContants.PROJECT_PATH_IMG_IMPORTED;
		File[] files=new File(path).listFiles();
		boolean ff=true;
		if(files!=null){
			for(File f:files){
				String s=f.getName().substring(0,f.getName().indexOf("_"));
				if(s.equals(aParm.getPaperNO())){
					map.put("path",request.getSession().getServletContext().getContextPath() + File.separator + PathContants.PROJECT_PATH_IMG_IMPORTED +File.separator+f.getName());
					map.put("photoName", f.getName());
					ff=false;
					logger.debug("图片路径【{}】",map.get("path"));
					break;
				}
			}
		}
		//照片已上传ftp
		if(ff){
			logger.debug("去FTP获取照片【{}】",PathContants.FTP_PATH_PHOTO);
			List<FTPFile> ftpFiles=FtpUtil.getFileList(PathContants.FTP_URL,PathContants.FTP_PORT , PathContants.FTP_USERNAME, PathContants.FTP_PASSWORD, PathContants.FTP_PATH_PHOTO);
			if(ftpFiles!=null&&ftpFiles.size()>0){
				for(FTPFile ftpFile:ftpFiles){
					if(ftpFile.getName().contains("_")){
						String s=ftpFile.getName().substring(0,ftpFile.getName().indexOf("_"));
						if(s.equals(aParm.getPaperNO())){//ftp://username:password@192.168.0.1:21/11/xx.jpg
							String ftpPath="ftp://"+PathContants.FTP_USERNAME+":"+PathContants.FTP_PASSWORD+"@"+PathContants.FTP_URL+":"+PathContants.FTP_PORT;
							if(PathContants.FTP_URL.equals("192.168.0.12")){
								
								map.put("path",ftpPath+PathContants.FTP_PATH_PHOTO+PathContants.separator+ftpFile.getName());
							}else{
								map.put("path",ftpPath+PathContants.FTP_PATH_PHOTO+PathContants.separator+ftpFile.getName());
							}
							map.put("photoName", ftpFile.getName());
						}
					}
					
				}
			}	
		}
		logger.debug("aParm"+aParm.toString());
		//20180511鱼洲杰 以下一行
		ActiveUser activeUser = (ActiveUser) SecurityUtils.getSubject().getSession().getAttribute("activeUser");
		map.put("Personal", p);
		map.put("AppParm", aParm);
		
		//20180511鱼洲杰 以下一行
		map.put("ActiveUser", activeUser);
		return map;

	}

	/**
	 * 更改时间格式
	 * @param date
	 * @return
	 */
	public static String dateFormat(Date date){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		return  sdf.format(date);
	}
	/**
	 * 获取收费费用值（弃用）
	 * @param parm
	 * @return
	 */
	@RequiresPermissions("applicationSingle:getNationInfo")
	@RequestMapping(value="/getfeeprinciple",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> getfeeprinciple(HttpServletRequest request ) {
		Map<String, Object> map=new HashMap<>();
		String cardCode=(String) request.getSession().getAttribute("cardCode");
		FeeRulesVo vo=new FeeRulesVo();
		//vo.setCardpName(cdm.queryCardCode(cardCode).getCardpName());
		vo.setCardpCode(cardCode);
		vo.setFeeType("1");//工本费代码
		FeeRules FeeRules=afs.queryFeeRulesByCardPCodeAndFeeType(vo);
		map.put("fee", FeeRules.getFeeBln());
		
		return map;

	}
	/**
	 * 判断是否打印采集单
	 * @param parm
	 * @return
	 */
	@RequiresPermissions("applicationSingle:judgementPrint")
	@RequestMapping(name="判断是否打印采集单,applicationSingle:judgementPrint",value="/judgementPrint",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> judgementPrint(HttpServletRequest request ) {
		Map<String, Object> map=new HashMap<>();
		boolean a=(boolean) request.getSession().getAttribute("flag");
		if(!a){
			map.put("statusCode", "300");
			map.put("message", "请先打印采集单");
		}
		return map;

	}
}


